package com.it.ems.service.impl;

import com.it.ems.entity.Address;
import com.it.ems.mapper.AddressMapper;
import com.it.ems.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService {
    
    @Autowired
    private AddressMapper addressMapper;
    
    @Override
    public Address findById(Long id) {
        return addressMapper.findById(id);
    }
    
    @Override
    public List<Address> findByUserId(Long userId) {
        return addressMapper.findByUserId(userId);
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(Address address) {
        return addressMapper.insert(address) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean update(Address address) {
        return addressMapper.update(address) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(Long id) {
        return addressMapper.delete(id) > 0;
    }
    
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByUserId(Long userId) {
        return addressMapper.deleteByUserId(userId) > 0;
    }
} 